package com.ykt.controller;

import com.jfinal.ext.route.ControllerBind;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.ykt.model.Admin;
import com.ykt.model.PayRecord;

import java.util.Map;

@ControllerBind(controllerKey="/payRecord")
public class PayRecordController extends BaseController<PayRecord> {

	public PayRecordController() {
		super(PayRecord.class);
	}
	
	public void grid() {
        int page = getParaToInt("page", 1);
        int rows = this.getParaToInt("rows", 20);
        
        Admin admin = getCurrentUser();
        Map<String, String> params = this.toParaMap();
        if(admin.get(Admin.role_ids)!=null && admin.getStr(Admin.role_ids).equals("6")){
        	params.put("EQ_o.shop_id",admin.getInt(Admin.shopId).toString());
        }
        
        try {
            Page<PayRecord> data = PayRecord.dao.pageFindModel(page, rows, params);
            rendDataGrid(data);
        } catch (Exception e) {
            log.error(e);
            rendJson(false, e.getMessage());
        }
    }
	
	@Override
	public void view() {
        Long id = this.getParaToLong(0, 0L);
        if (id != null && id != 0L)
            this.setAttr("po", PayRecord.dao.getViewById(id));
        else
            this.setAttr("po", new Record());
    }
}
